<?php
     include_once('../src/classes/class.mysql.php');  
     
     session_start();
     
     $db = new MySQL();

     $comtec_id_order = $_GET['comtec_id_order'];
     $token = $_GET['token'];
     $type = $_GET['type'];
     
     $tsql = "SELECT m.cod_mainteiner,o.comtec_id_machine,CONCAT_WS(' ',r.name,r.lastname1,r.lastname2) as encargado,
                     o.notes,o.operation_type,o.cod_order,o.tasks,o.comtec_id_mainteiner,
                     DATE_FORMAT(o.order_start_date,'%d/%m/%Y') as order_date1,
                     DATE_FORMAT(o.order_end_date,'%d/%m/%Y') as order_date2 
              FROM   (orders AS o INNER JOIN machines AS m ON o.comtec_id_machine = m.comtec_id_machine)
                     INNER JOIN responsible as r ON o.comtec_id_responsible = r.comtec_id_responsible
              WHERE  o.comtec_id_order = $comtec_id_order";
     
     $result = $db->fetch_array($db->query($tsql));
     
     $comtec_id_mainteiner = $result['comtec_id_mainteiner'];
     $encargado = $result['encargado'];
     $comtec_id_machine = $result['comtec_id_machine'];
     $operation_type = $result['operation_type'];    
     $cod_mainteiner = $result['cod_mainteiner'];
     $cod_order = $result['cod_order'];
     $tasks = $result['tasks'];
     $notes = $result['notes'];
     $order_date1 = $result['order_date1'];
     $order_date2 = $result['order_date2'];
   
     function extra($x){
      if ($x <= 9){
       $x = "0".$x;   
      }   
      return $x;   
     }
     
    switch ($operation_type) {
      case 1: 
             $operation_type = "Mantenci&oacute;n";
      break;
      case 2: 
             $operation_type = "Emergencia";
      break; 
      case 3: 
             $operation_type = "Instalaci&oacute;n";
      break;
      case 4: 
             $operation_type = "Reparaci&oacute;n";
      break;
     }
 
?>
<fieldset class="curved">
 <legend>Ver</legend>
 <table style="margin: 10px auto; border-spacing: 10px;">
        <tr><td width="200"><label>M&aacute;quina</label></td>
            <td><input type="text" DISABLED size="40" value="<?=$cod_mainteiner;?>" /></td>
            <td width="200"><label>C&oacute;digo</label></td>
            <td><input type="text" DISABLED size="40" value="<?=$cod_order;?>" /></td>
        </tr>
        <tr>
            <td width="200"><label>Tipo de operaci&oacute;n</label></td>
            <td>
                <input type="text" size="40" DISABLED value=<?=$operation_type?> />
            </td>
            <td width="200"><label>Encargado</label></td>
            <td colspan="4"><input type="text" DISABLED size="40" value="<?=$encargado?>"/></td>
           </tr>
           <tr>
               <td width="200"><label>Tareas</label></td>
               <td colspan=4><textarea id="tasks" rows="6" cols="91" readonly="readonly" style="resize:none"><?=$tasks?></textarea></td>
           </tr>
           <tr>
                <td width="200"><label>Notas</label></td>
                <td colspan=4><textarea id="notes" rows="2" cols="91" readonly="readonly" style="resize:none"><?=$notes?></textarea></td>
           </tr>
           <tr>              
               <td width="200"><label>Fecha de inicio</label></td>
               <td>
                   <input type="text" size="40" DISABLED value=<?=$order_date1?> >
               </td>
           </tr>   
           <tr>
               <td width="200">
                   <label>Fecha de fin</label>
               </td>
               <td>
                   <input type="text" size="40" DISABLED value=<?=$order_date2?> >
               </td>
           </tr>       
           <? if($type == 1){ ?>
              <tr><td><input type="button" value="Regresar" onclick="javascript:loadOrders(<?=$comtec_id_machine?>);" /></td></tr>
           <? }  elseif ($type == 2) { ?>
              <tr><td><input type="button" value="Regresar" onclick="javascript:loadHome();" /></td></tr>   
           <? }  elseif ($type == 3) { ?>
              <tr><td><input type="button" value="Regresar" onclick="javascript:goBackSearch();" /></td></tr>
           <?} ?>   
          </table>
</fieldset>
